//
//  LogHelper.swift
//  test-ios
//
//  Created by wyz5204 on 2023/7/12.
//

import Foundation
import CocoaLumberjack

class Logger {
    
    private static let TOP_CORNER     = "┌";
    private static let MIDDLE_CORNER  = "├";
    private static let LEFT_BORDER    = "│ ";
    private static let BOTTOM_CORNER  = "└";
    private static let SINGLE_DIVIDER   =
    "─";
    private static let SIDE_DIVIDER   =
    "────────────────────────────────────────────────────────";
    private static let MIDDLE_DIVIDER =
    "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄";
    private static let TOP_BORDER     = TOP_CORNER + SIDE_DIVIDER;
    private static let MIDDLE_BORDER  = MIDDLE_CORNER +  MIDDLE_DIVIDER;
    private static let BOTTOM_BORDER  = BOTTOM_CORNER + SIDE_DIVIDER ;
    
    static let sharedInstance: Logger = {
        let instance = Logger()
        DDLog.add(DDOSLogger.sharedInstance) // Uses os_log
#if DEBUG
        let fileLogger: DDFileLogger = DDFileLogger() // File Logger
        fileLogger.rollingFrequency = 60 * 60 * 24 // 24 hours
        fileLogger.logFileManager.maximumNumberOfLogFiles = 7
        DDLog.add(fileLogger)
#endif
        return instance
    }()
    
    
    static func e(_ numbers: Any...){
        var result = "\n\(TOP_BORDER)"
        result += "\n\(LEFT_BORDER)\(Thread.current.description)"
        result += "\n\(MIDDLE_BORDER)"
        for item in numbers {
            result += "\n\(MIDDLE_CORNER) \(item)"
        }
        result += "\n\(BOTTOM_BORDER)"
        DDLogError(result)
    }
}
